﻿#region Using Directives

using JetBrains.DocumentModel;
using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Daemon.CSharp.Stages;
using Microsoft.StyleCop;

#endregion

namespace CCN.StyleCopPlugin.Highlights
{
    /// <summary>
    /// Highlighting to display a <c>StyleCop</c> violation error
    /// </summary>
    [StaticSeverityHighlighting(Severity.WARNING, OverlapResolve = OverlapResolveKind.WARNING)]
    public class StyleCopViolation : CSharpHighlightingBase, IHighlighting
    {
        private const string MESSAGE = "StyleCop: {0} | {1}";

        private readonly DocumentRange _range;
        private readonly ViolationEventArgs _violation;

        /// <summary>
        /// Initializes a new instance of the <see cref="StyleCopViolation"/> class.
        /// </summary>
        /// <param name="violation">The <see cref="Microsoft.StyleCop.ViolationEventArgs"/> instance containing the event data.</param>
        /// <param name="range">The range.</param>
        public StyleCopViolation(ViolationEventArgs violation, DocumentRange range)
        {
            _violation = violation;
            _range = range;
        }

        /// <summary>
        /// Gets the range.
        /// </summary>
        /// <value>The range.</value>
        public override DocumentRange Range
        {
            get
            {
                return _range;
            }
        }

        #region IHighlighting Members

        /// <summary>
        /// Message for this highlighting to show in tooltip and in status bar (if <see cref="P:JetBrains.ReSharper.Daemon.HighlgihtingAttributeBase.ShowToolTipInStatusBar"/> is <c>true</c>)
        /// </summary>
        /// <value></value>
        public string ErrorStripeToolTip
        {
            get
            {
                return ToolTip;
            }
        }

        /// <summary>
        /// Specifies the offset from the Range.StartOffset to set the cursor to when navigating
        /// to this highlighting. Usually returns <c>0</c>
        /// </summary>
        /// <value></value>
        public int NavigationOffsetPatch
        {
            get
            {
                return 0;
            }
        }

        /// <summary>
        /// Message for this highlighting to show in tooltip and in status bar (if <see cref="P:JetBrains.ReSharper.Daemon.HighlgihtingAttributeBase.ShowToolTipInStatusBar"/> is <c>true</c>)
        /// To override the default mechanism of tooltip, mark the implementation class with
        /// <see cref="T:JetBrains.ReSharper.Daemon.DaemonTooltipProviderAttribute"/> attribute, and then this property will not be called
        /// </summary>
        /// <value></value>
        public string ToolTip
        {
            get
            {
                return string.Format(MESSAGE, _violation.Violation.Rule.CheckId, _violation.Message);
            }
        }

        #endregion
    }
}